package com.maserb.monitor.repository.schoolStudent;

import com.maserb.monitor.entity.schoolStudent.SchoolStudentParentEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SchoolStudentParentRepository extends JpaSpecificationExecutor<SchoolStudentParentEntity>
        , PagingAndSortingRepository<SchoolStudentParentEntity, String> {

    SchoolStudentParentEntity findByUserName(String userName);

    @Query(value = "select p from SchoolStudentEntity s left join s.parent p where s.orgId=?1 and s.parent<>null")
    List<SchoolStudentParentEntity> findByClazzId(String clazzId);

    @Query(value = "select p from SchoolStudentEntity s left join s.parent p where s.schoolId=?1 and s.parent<>null")
    List<SchoolStudentParentEntity> findBySchoolId(String schoolId);

    @Query(value = "select p,s from SchoolStudentEntity s left join s.parent p where s.orgId=?1 and s.parent<>null")
    List<Object[]> findObjectByClazzId(String clazzId);

    SchoolStudentParentEntity findFirstByRealName(String realName);
}